#!/bin/bash
# installation emqx

. ./public_functions &>/dev/null #公共函数库
. /tmp/public_functions &>/dev/null #公共函数库

emqx_Version="emqx-centos7-4.3.11-amd64.zip"
emqx_catalog="emqx"

logW "下载${emqx_Version}"
logY "curl -# -L --output /tmp/${emqx_Version} --remote-name https://www.emqx.com/zh/downloads/broker/v4.3.11/${emqx_Version}"
curl -# -L  --output /tmp/${emqx_Version} --remote-name https://www.emqx.com/zh/downloads/broker/v4.3.11/${emqx_Version}
#curl -# -L --remote-name https://www.emqx.com/zh/downloads/broker/v4.3.11/${emqx_Version}.sha256
#curl -# -L --remote-name https://www.emqx.com/zh/downloads/broker/v4.3.11/emqx-centos7-4.3.11-amd64.rpm
#curl -# -L --remote-name https://www.emqx.com/zh/downloads/broker/v4.3.11/emqx-centos7-4.3.11-amd64.rpm.sha256
checkTF

logW "安装unzip"
logY ". yum install unzip -y"
yum install unzip -y
checkTF

logW ". 解压emqx到 /home"
logY "unzip /tmp/${emqx_Version} -d /home"
rm -rf /home/${emqx_catalog}
unzip /tmp/${emqx_Version} -d /home
checkTF

logW ". 启动empx"
logY "/home/emqx/bin/emqx start"
/home/emqx/bin/emqx start
checkTF

logW ". 放行18083端口"
  get_Firewalld_status #23#
    if [[ $? -eq 0 ]]; then
      logY "firewall-cmd --zone=public --add-port="18083"/"tcp" --permanent" #1-20#
      firewall-cmd --zone=public --add-port="18083"/"tcp" --permanent 2>/dev/null
      firewall-cmd --reload &>/dev/null
      echo ""
    else
      logR "防火墙未开启" #1-20#
      echo ""
    fi

logW "请访问：http://{ip}:18083"
logW "默认用户名/密码：admin/public"
echo

